package controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import pojo.SysRole;
import service.SysRoleService;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/role")
public class SysRoleController extends BaseController {
    @Resource
    private SysRoleService sysRoleService;

    @ResponseBody
    @GetMapping("/simple")
    public Object getRoleList(){
        List<SysRole> list=sysRoleService.getRoles();
        return list;
    }
    @RequestMapping("/list")
    public String selectAllRoles(Model model){
        List<SysRole> list=sysRoleService.getRoles();
        model.addAttribute("roleList",list);
        return "sysRole/list";
    }

    @RequestMapping("/toAdd")
    public String toAdd(){
        return "sysRole/add";
    }

    @RequestMapping("/add")
    public String add(String code,String roleName){
        SysRole role = new SysRole();
        role.setCode(code);
        role.setRoleName(roleName);
        if(sysRoleService.add(role)>0){
            return "role/list";
        }
        return "sysRole/add";
    }
}
